home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Windows / SAMPLES / DEFORMER / DEFS / COMDEFS.CPP next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  5.7 KB  |  209 lines

  1. // Copyright (c)1995 Ray Dream, Inc. All Rights Reserved.
  2. /* $Id: COMDefS.cpp 1.8 1997/06/28 05:13:42 damien Exp $ */
  3.  
  4. ////////////////////////////////////////////////////////////////////////
  5. //  Deformer Example                                                  //
  6. //--------------------------------------------------------------------//
  7. //   Implementation of the Deformer Interface                         //
  8. //////////////////////////////////////////////////////////////////////// 
  9.  
  10.  
  11. #ifndef __COMDEFS__
  12. #include "COMDEFS.h"
  13. #endif
  14.  
  15. #ifndef __DEFSDLL__
  16. #include "DEFSDLL.h"
  17. #endif
  18.  
  19. #ifndef __3DCOFAIL__
  20. #include "3DCoFail.h"
  21. #endif
  22.  
  23. #undef INTERFACE
  24. #define INTERFACE Deformer
  25. // Constructor / Destructor of the C++ Object :
  26. Deformer::Deformer() {
  27.   fCRef=0; // Reference Counter
  28.   // Data initialisation :
  29.   fData.fAxis = kAxisZ;
  30.   fData.fUBegScale = 1.0;
  31.   fData.fUEndScale = 1.0;
  32.   fData.fVBegScale = 1.0;
  33.   fData.fVEndScale = 1.0;
  34.   fData.fBoundingBox.fMin[0] = 0.0;
  35.   fData.fBoundingBox.fMin[1] = 0.0;
  36.   fData.fBoundingBox.fMin[2] = 0.0;
  37.   fData.fBoundingBox.fMax[0] = 0.0;
  38.   fData.fBoundingBox.fMax[1] = 0.0;
  39.   fData.fBoundingBox.fMax[2] = 0.0;
  40.   }
  41.   
  42. Deformer::~Deformer() {
  43.   global_count_Obj--; 
  44.   }
  45.   
  46. // IUnknown Interface :
  47. HRESULT Deformer::QueryInterface(THIS_ REFIID riid,LPVOID* ppvObj) {
  48.   *ppvObj=NULL;
  49.   
  50.   // The Deformer knows the interfaces of the parent Objects
  51.   if (IsEqualIID(riid, IID_IUnknown))
  52.     *ppvObj=(LPVOID)this;
  53.   else if (IsEqualIID(riid, IID_I3DExDeformer2))
  54.     *ppvObj=(LPVOID)(I3DExDeformer2*)this;
  55.   else if (IsEqualIID(riid, IID_I3DExDataExchanger))
  56.     *ppvObj=(LPVOID)(I3DExDataExchanger*)this;
  57.   else if (IsEqualIID(riid, IID_I3DExtension))
  58.     *ppvObj=(LPVOID)(I3DExtension*)this;
  59.     
  60.   // we must add reference if we return an interface
  61.   if (*ppvObj!=NULL) {
  62.     ((LPUNKNOWN)*ppvObj)->AddRef();
  63.     return NOERROR;
  64.     }
  65.   else {
  66.     return ResultFromScode(E_NOINTERFACE);
  67.     }
  68.   }
  69.  
  70. ULONG Deformer::AddRef(THIS) {
  71.   return fCRef++;
  72.   }
  73.   
  74. ULONG Deformer::Release(THIS) {
  75.   ULONG UnreleaseObject=fCRef--;
  76.   
  77.   if (fCRef==0)
  78.      delete this; // No reference left, so destroy the object
  79.   
  80.   return UnreleaseObject;
  81.   // local variable used, because fCRef can be destroyed before.
  82.   }
  83.   
  84. // I3DExtension methods :
  85. I3DExtension* Deformer::Clone(THIS) {
  86.   Deformer* theClone = new Deformer;
  87.   if (theClone) {
  88.     theClone->AddRef();
  89.     theClone->fData=fData; // copy the DeformerData
  90.     }                               
  91.   return (I3DExtension*)theClone;
  92.   }   
  93.  
  94. HRESULT Deformer::ShellUtilitiesInit(THIS_ IShUtilities* shellUtilities) {
  95.   InitCoFailure(shellUtilities);
  96.   return NOERROR;
  97.   }
  98.  
  99. // I3DExDataExchanger methods :
  100. ExtensionDataMap* Deformer::GetExtensionDataMap(THIS) {
  101.   return NULL;
  102.   }
  103.  
  104. void* Deformer::GetExtensionDataBuffer(THIS) {
  105.   return &fData; // used by the shell to set the new parameters
  106.   }
  107.   
  108. HRESULT Deformer::ExtensionDataChanged(THIS) {
  109.   return NOERROR;
  110.   }
  111.  
  112. HRESULT Deformer::HandleEvent(THIS_ ULONG SourceID) {
  113.   return ResultFromScode(E_NOTIMPL);
  114.   }
  115.  
  116. short Deformer::GetResID(THIS) {
  117.   return 140; // this is the view ID in the resource file.
  118.   }
  119.   
  120. // I3DExDeformer methods :
  121.  
  122. HRESULT Deformer::SetBBox(THIS_ BOX3D *bbox) {
  123.   fData.fBoundingBox=*bbox;
  124.   return NOERROR;
  125.     }
  126.  
  127. HRESULT Deformer::DeformPoint(THIS_ VECTOR3D* point,VECTOR3D* result) {
  128.     short u,v,w;
  129.   NUM3D wrelative;
  130.   if(fData.fAxis==kAxisX) {
  131.         u=1; // Y Axis
  132.     v=2; // Z Axis
  133.     w=0; // X Axis
  134.         }
  135.   else if (fData.fAxis==kAxisY) {
  136.         u=2; // Z Axis
  137.     v=0; // X Axis
  138.     w=1; // Y Axis
  139.         }
  140.   else {
  141.         u=0; // X Axis
  142.     v=1; // Y Axis
  143.     w=2; // Z Axis
  144.         }
  145.   if ((fData.fBoundingBox.fMax[w]-fData.fBoundingBox.fMin[w])==0.0) {
  146.         (*result)[0]=(*point)[0];
  147.         (*result)[1]=(*point)[1];
  148.         (*result)[2]=(*point)[2];
  149.     return NOERROR;
  150.         }
  151.   wrelative=((*point)[w] - fData.fBoundingBox.fMin[w])/(fData.fBoundingBox.fMax[w]-fData.fBoundingBox.fMin[w]);
  152.   if ((fData.fUEndScale+fData.fUBegScale)==0.0) {
  153.         (*result)[u]=0.0;
  154.         }
  155.   else {
  156.     (*result)[u] = (*point)[u] * (fData.fUBegScale + wrelative * (fData.fUEndScale-fData.fUBegScale));
  157.         }
  158.   if ((fData.fVEndScale+fData.fVBegScale)==0.0) { 
  159.         (*result)[v]=0.0;
  160.         }
  161.   else {
  162.     (*result)[v] = (*point)[v] * (fData.fVBegScale + wrelative * (fData.fVEndScale-fData.fVBegScale));
  163.         }
  164.   (*result)[w] = (*point)[w];
  165.   return NOERROR;
  166.     }
  167.  
  168. HRESULT Deformer::DeformFacetMesh(THIS_ NUM3D lod,const FacetMesh &in,FacetMesh &out) {
  169.     return ResultFromScode(E_NOTIMPL);
  170.     }
  171.  
  172. HRESULT Deformer::DeformBBox(THIS_ const BOX3D &in,BOX3D &out) {
  173.     const VECTOR3D *borne[2];
  174.     VECTOR3D point, deformed;
  175.     borne[0]=&in.fMin;
  176.     borne[1]=&in.fMax;
  177.     int ii, jj, kk, ll;
  178.     out=in;
  179.     for (ii=1; ii>=0; ii--) {
  180.         point[0]=(*borne[ii])[0];
  181.         for (jj=1; jj>=0; jj--) {
  182.             point[1]=(*borne[jj])[1];
  183.             for (kk=1; kk>=0; kk--) {
  184.                 point[2]=(*borne[kk])[2];
  185.                 DeformPoint(&point, &deformed);
  186.                 for (ll=2; ll>=0; ll--) {
  187.                     if (deformed[ll] < out.fMin[ll]) out.fMin[ll]=deformed[ll];
  188.                     if (deformed[ll] > out.fMax[ll]) out.fMax[ll]=deformed[ll];
  189.                     }
  190.                 }
  191.             }
  192.         }
  193.         
  194.     // (damien) the BBox is not necessarely the one of the deformed object
  195.     // it can be the bbox of a child of this object
  196.     //  the following code is then wrong.
  197.     /*
  198.     NUM3D maxU=(fData.fUBegScale > fData.fUEndScale) ? fData.fUBegScale : fData.fUEndScale;
  199.     NUM3D maxV=(fData.fVBegScale > fData.fVEndScale) ? fData.fVBegScale : fData.fVEndScale;
  200.     out.fMin[0]=in.fMin[0]*maxU;
  201.     out.fMin[1]=in.fMin[1]*maxV;
  202.     out.fMin[2]=in.fMin[2];
  203.     out.fMax[0]=in.fMax[0]*maxU;
  204.     out.fMax[1]=in.fMax[1]*maxV;
  205.     out.fMax[2]=in.fMax[2];
  206.     */
  207.     return S_OK;
  208.     }
  209.